<?php
class DisassistantAction extends AdminAction{
	
    //食谱列表中的类别
    public static $type = array(1=>'炒菜', 2=>'粥类');
    //食谱列表中的营养分类
    public static $nutrition = array(1=>'主荤', 2=>'主素', 3=>'荤素搭配');
    
    public function _empty($name){
            $this->display('Public:notfound');
    }
    
    /**
     * 疾病App
     * @auther zhenggangwei@xywy.com
     * @version 2015-02-05
     */
	public function disApp() {
	    $js_dialog = Resource::getStatic('dialog','js');
	    $pagesize = C('PERPAGE');
	    $page = I('page',1);
	    $Model = M('App');
	    $total = $Model->count();
	    $list = $Model->select();
	    $mypage = new Pager($total,$pagesize,$page,'/Admin/Disassistant/disApp');
	    $this->assign('js_dialog',$js_dialog);
	    $this->assign('list',$list);
	    $this->assign('page',$mypage->show());
	    $this->assign('empty','<tr><td colspan="11" style="text-align:center;">没有找到任何数据</td></tr>');
	    $this->display();
	}
    
	/**
	 * 添加疾病App
	 * @author zhenggangwei@xywy.com
	 * @version 2015-02-05
	 */
	public function addDisApp(){
	    $model = M('App');
	    $id = I('id');
	    $appname = I('appname');
	    $unique=$model->where('appname="'.$appname.'"')->find();
	    if ($unique) {
	        $this->error('APP命名重复，请核实后创建');
	    }
	    $adduser = session('dis_realname');
	    if ($id) {
            $data = array('id'=>$id,'appname'=>$appname,'adduser'=>$adduser);
            $res = $model->save($data);
	    } else {
    	    $appno = createcode();
            $create_time = time();
            $data = array('appname'=>$appname,'appno'=>$appno,'adduser'=>$adduser,'create_time'=>$create_time);
            $res = $model->add($data);
	    }
	    if ($res) {
	        $this->success('APP创建成功');
	    } else {
	        $this->error('APP创建失败');
	    }
	    
	}
	
    /**
     * 疾病饮食
     * @auther zhenggangwei@xywy.com
     * @version 2015-02-05
     */
	public function disFood() {
	    $js_dialog = Resource::getStatic('dialog','js');
	    $pagesize = C('PERPAGE');
	    $page = I('page',1);
	    $Model = M('Eatingdisorders');
	    $total = $Model->count();
	    $list = $Model->select();
	    $mypage = new Pager($total,$pagesize,$page,'/Admin/Disassistant/disFood');
	    $apps = $this->getApp();
	    $this->assign('js_dialog',$js_dialog);
	    $this->assign('type',self::$type);
	    $this->assign('nutrition',self::$nutrition);
	    $this->assign('list',$list);
	    $this->assign('apps',$apps);
	    $this->assign('page',$mypage->show());
	    $this->assign('empty','<tr><td colspan="11" style="text-align:center;">没有找到任何数据</td></tr>');
	    $this->display();
	}
    
	/**
	 * 添加食谱
	 * @author zhenggangwei@xywy.com
	 * @version 2015-02-05
	 */
	public function addDisFood(){
	    if (I('submit')) {
	        $model = M('Eatingdisorders');
	        $model->create();
	        $model->update_time = $model->create_time = time();
	        $model->adduser = session('dis_realname');
	        $res = $model->add();
	        if ($res) {
	            $this->success('数据添加成功','__GROUP__/Disassistant/disFood');
	        } else {
	            $this->error('数据添加失败','__GROUP__/Disassistant/disFood');
	        }
	    } else {
    	    $js_dialog = Resource::getStatic('dialog','js');
	        $this->assign('js_dialog',$js_dialog);
            $this->assign('type',self::$type);
    	    $this->assign('nutrition',self::$nutrition);
    	    $this->display();
	    }
	}

	/**
	 * 编辑食谱
	 * @author zhenggangwei@xywy.com
	 * @version 2015-02-05
	 */
	public function editDisFood(){
	    $id = I('id');
        $model = M('Eatingdisorders');
	    if (I('submit')) {
	        $model->create();
	        $model->update_time = time();
	        $model->adduser = session('dis_realname');
	        $res = $model->save();
	        if ($res) {
	            $this->success('数据修改成功','__GROUP__/Disassistant/disFood');
	        } else {
	            $this->error('数据修改失败','__GROUP__/Disassistant/disFood');
	        }
	    } else {
	        $list = $model->where('id='.$id)->find();
    	    $js_dialog = Resource::getStatic('dialog','js');
	        $this->assign('js_dialog',$js_dialog);
            $this->assign('type',self::$type);
    	    $this->assign('nutrition',self::$nutrition);
            $this->assign('list',$list);
    	    $this->display();
	    }
	}
	
	/**
	 * 食谱推送日志
	 * @author zhenggangwei@xywy.com
	 * @version 2015-02-05
	 */
	public function disRecipesPush(){
	    $date1 = I('date1');
	    $date2 = I('date2');
	    $appname = I('appname');
	    $where = array();
	    $params = '';
	    if (!empty($date1)) {
	        $params .= '/date1/'.$date1;
	        $where['a.create_time'] = array('egt',strtotime($date1));
	    }
	    if (!empty($date2)) {
	        $params .= '/date2/'.$date2;
	        $where['a.create_time'] = array('elt',strtotime($date2.' 23:59:59'));
	    }
	    if (!empty($date1) && !empty($date2)) {
	        $where['a.create_time'] = array('between',array(strtotime($date1),strtotime($date2.' 23:59:59')));
	    }
	    if (!empty($appname)) {
	        $params .= '/appname/'.$appname;
	        $where['c.appname'] = array('eq',$appname);
	    }
	    $pagesize = C('PERPAGE');
	    $page = I('page',1);
	    $model = M('Recipepush');
	    $list = $model->alias('a')->join('dis_eatingdisorders as b on a.fid=b.id')->join('dis_app as c on a.aid=c.id')->field('a.id,a.create_time,a.adduser,b.recipename,b.type,b.nutrition,c.appname')->where($where)->limit(($page-1)*$pagesize,$pagesize)->select();
	    $total = $model->alias('a')->join('dis_app as c on a.aid=c.id')->where($where)->count();
	    $mypage = new Pager($total,$pagesize,$page,'/Admin/Disassistant/disRecipesPush'.$params);
	    $apps = $this->getApp();
	    $js_calendar = Resource::getStatic('calendar','js');
	    $this->assign('js_calendar',$js_calendar);
	    $this->assign('type',self::$type);
	    $this->assign('nutrition',self::$nutrition);
	    $this->assign('list',$list);
	    $this->assign('date1',$date1);
	    $this->assign('date2',$date2);
	    $this->assign('appname',$appname);
	    $this->assign('page',$mypage->show());
	    $this->assign('empty','<tr><td colspan="11" style="text-align:center;">没有找到任何数据</td></tr>');
	    $this->display();
	}

	/**
	 * 添加食谱推送
	 * @author zhenggangwei@xywy.com
	 * @version 2015-02-05
	 */
	public function addFoodPush(){
        $app = I('app');
        $fid = I('fid');
        $model = M('Recipepush');
        $res = true;
        foreach ($app as $val) {
            $exit = $model->where('fid='.$fid.' and aid='.$val)->find();
            if (empty($exit)) {
                $data = array('fid'=>$fid,'aid'=>$val,'create_time'=>time(),'adduser'=>session('dis_realname'));
                $res = $model->add($data);
            }
        }
        if ($res) {
            $this->success('数据添加成功','__GROUP__/Disassistant/disRecipesPush');
        } else {
            $this->error('数据添加失败','__GROUP__/Disassistant/disRecipesPush');
        }
	}
	
	/**
	 * 获取当日没有推送的app名称
	 */
	public function selectDisAppname(){
	    $pagesize = C('PERPAGE');
	    $page = I('page',1);
	    $date = date('Y-m-d',time());
	    $start = strtotime($date);
	    $end = strtotime($date.' 23:59:59');
	    $model = M('Recipepush');
	    $where['create_time'] = array('between',array($start,$end));
	    $appid = $model->distinct(true)->field('aid')->where($where)->select();    
	    $arrappid = array();
	    foreach ($appid as $v) {
	        $arrappid[] = $v['aid'];
	    }
	    $strappid = implode(',',$arrappid);
	    $app = M('App');
	    $map['id'] = array('not in',$strappid);
	    $appname = $app->where($map)->field('id,appname')->select();
	    $total = $app->where($map)->count();
	    $mypage = new Pager($total,$pagesize,$page,'/Admin/Disassistant/selectDisAppname');
	    $this->assign('list',$appname);
	    $this->assign('page',$mypage->show());
	    $this->assign('empty','<tr><td colspan="11" style="text-align:center;">没有找到任何数据</td></tr>');
	    $this->display();
	}
	
	/**
	 * 饮食禁忌列表
	 * @zhenggangwei@xywy.com
	 * @version 2015-02-09
	 */
	public function disFoodTaboo(){
	    $pagesize = C('PERPAGE');
	    $page = I('page',1);
	    $model = M('Foodtaboo');
	    $list = $model->alias('a')->join('dis_app as b on a.appname=b.id')->field('a.id,a.properdiet,a.diettaboo,a.update_time,a.adduser,b.appname')->select();
	    $total = $model->count();
	    $mypage = new Pager($total,$pagesize,$page,'/Admin/Disassistant/disFoodTaboo');
	    $this->assign('list',$list);
	    $this->assign('page',$mypage->show());
	    $this->assign('empty','<tr><td colspan="11" style="text-align:center;">没有找到任何数据</td></tr>');
	    $this->display();
	}
	
	/**
	 * 添加疾病饮食禁忌
	 * @zhenggangwei@xywy.com
	 * @version 2015-02-09
	 */
	public function addDisFoodTaboo(){
	    if (I('submit')) {
	        $appname = I('appname');
	        $model = M('Foodtaboo');
	        $exit = $model->where('appname='.$appname)->find();
	        if ($exit) {
	            $this->error('该疾病APP已经存在','__GROUP__/Admin/Disassistant/disFoodTaboo');
	            return false;
	        }
	        $model->create();
	        $model->create_time = $model->update_time = time();
	        $model->adduser = session('dis_realname');
	        $res = $model->add();
	        if ($res) {
	            $this->success('数据添加成功','__GROUP__/Admin/Disassistant/disFoodTaboo');
	        } else {
	            $this->error('数据添加失败','__GROUP__/Admin/Disassistant/disFoodTaboo');
	        }
	    } else {
    	    $apps = $this->getApp();
    	    $this->assign('apps',$apps);
    	    $this->display();
	    }
	}
	
	/**
	 * 修改疾病饮食禁忌
	 * @zhenggangwei@xywy.com
	 * @version 2015-02-09
	 */
	public function editDisFoodTaboo(){
        $id = I('id');
        $model = M('Foodtaboo');
        if (I('submit')) {
            $appname = I('appname');
	        $exit = $model->where('appname='.$appname)->find();
	        if ($exit) {
	            $this->error('该疾病APP已经存在','__GROUP__/Admin/Disassistant/disFoodTaboo');
	            return false;
	        }
	        $model->create();
	        $model->update_time = time();
	        $model->adduser = session('dis_realname');
	        $res = $model->save();
	        if ($res) {
	            $this->success('数据修改成功','__GROUP__/Admin/Disassistant/disFoodTaboo');
	        } else {
	            $this->error('数据修改失败','__GROUP__/Admin/Disassistant/disFoodTaboo');
	        }
        } else {
            $list = $model->where('id='.$id)->find();
            $apps = $this->getApp();
            $this->assign('apps',$apps);
            $this->assign('list',$list);
            $this->display();
        }
	}
	
	/**
	 * 获取app
	 * @zhenggangwei@xywy.com
	 * @version 2015-02-09
	 */
	public function getApp(){
	    $model = M('App');
	    $list = $model->field('id,appname')->select();
	    return $list;
	}
    
    /**
     * 疾病测试标准
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-09
     */
	public function disTest(){
		$Model=M('teststandard');
		$list = $Model->field('`id`,`resultname`,`sshrinkage`,`eshrinkage`,`sdiastole`,`ediastole`,`explain`,`if_show`,`update_time`,`adduser`,`create_time`')->order('id asc')->select();
		$this->assign('list',$list);
		$this->display();
	}
	
	/**
     * 添加&&修改疾病测试标准页面
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-05
     */
	public function disTestaddedit_save(){
		$id = I('id');
		$resultname = I('resultname');  //结果名称
		$sshrinkage = I('sshrinkage');  //收缩压始
		$eshrinkage = I('eshrinkage');  //收缩压末
		$sdiastole = I('sdiastole');  //舒张压始
		$ediastole = I('ediastole');  //舒张压末
		$explain = I('explain');  //结果说明
		$if_show0 = I('if_show0');  //第一次，是否显示提问按钮
		$if_show1 = I('if_show1');  //第二次，是否显示提问按钮
		$if_show2 = I('if_show2');  //第三次，是否显示提问按钮
		$if_show3 = I('if_show3');  //第四次，是否显示提问按钮
		$strresultname = implode('',$resultname);  //将数组变成字符串,判断resultname是否有值
		//判断结果名称的数组是否有值
		if (empty($strresultname)) {
		    echo '<script>alert("结果名称不能为空！");window.location.href=document.referrer;</script>';
		    return false;
		}
		
		$sshrinkageval = implode('',$sshrinkage);  //将数组变成字符串,判断收缩压始是否有值
		$eshrinkageval = implode('',$eshrinkage);  //将数组变成字符串,判断收缩压末是否有值
		//判断收缩压的数组是否有值
		if (empty($sshrinkageval) || empty($eshrinkageval)) {
		    echo '<script>alert("收缩压始末不能为空！");window.location.href=document.referrer;</script>';
		    return false;
		}
		
		$data=array(array('resultname'=>$resultname[0],'sshrinkage'=>$sshrinkage[0],'eshrinkage'=>$eshrinkage[0],'sdiastole'=>$sdiastole[0],'ediastole'=>$ediastole[0],'explain'=>$explain[0],'if_show'=>$if_show0),
					array('resultname'=>$resultname[1],'sshrinkage'=>$sshrinkage[1],'eshrinkage'=>$eshrinkage[1],'sdiastole'=>$sdiastole[1],'ediastole'=>$ediastole[1],'explain'=>$explain[1],'if_show'=>$if_show1),
					array('resultname'=>$resultname[2],'sshrinkage'=>$sshrinkage[2],'eshrinkage'=>$eshrinkage[2],'sdiastole'=>$sdiastole[2],'ediastole'=>$ediastole[2],'explain'=>$explain[2],'if_show'=>$if_show2),
					array('resultname'=>$resultname[3],'sshrinkage'=>$sshrinkage[3],'eshrinkage'=>$eshrinkage[3],'sdiastole'=>$sdiastole[3],'ediastole'=>$ediastole[3],'explain'=>$explain[3],'if_show'=>$if_show3));
    	$Modle = M('teststandard');
    	$str = implode('',$id);  //将数组变成字符串,判断id是否有值
    	if(!empty($str)){   //修改
			foreach ($id as $kid=>$kval) {
				$data[$kid]['update_time'] = time();  //更新时间
				foreach ($data as $kdata=>$vald){
					if($kid==$kdata){
						$Modle->where('id='.$id[$kid])->save($data[$kdata]);
					}
				}
			}
		}else{   //添加
			foreach ($data as $kdata=>$vald){
				if($vald){
					$data[$kdata]['adduser'] = session('dis_realname');  //添加者
					$data[$kdata]['create_time'] = time();  //创建时间
					$Modle->add($data[$kdata]);
				}
			}
		}
		$this->success('保存成功！', '/Admin/Disassistant/disTest');
	}
	
	/**
     * 疾病症状管理
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function disSymptom(){
		$perpage = C('PERPAGE');  //每页显示的页数
		$page = I('page',1);  //当前的页数
		$total = 0; //初始化总共显示的条数
		$Model = M('symptomsdisease');
		$aapmodel = M('app');
		$list = $Model->field('`id`,`appname`,`symptom`,`update_time`,`adduser`,`create_time`')->order('id desc')->limit(($page-1)*$perpage, $perpage)->select();
    	foreach ($list as $key=>$val){
    		$appname = $aapmodel->field('`appname`')->where('`id`='.$val['appname'])->find();
    		$list[$key]['appname']=$appname['appname'];
    	}
		$total = $Model->count();
		$mypage = new Pager($total,$perpage,$page,'/Admin/Disassistant/disSymptom');
		$js_file = Resource::getStatic('dialog','js');
		$this->assign('list',$list);
		$this->assign('dialog',$js_file);
		$this->assign('page',$mypage->show());
		$this->assign('empty','<tr><td colspan="7" style="text-align:center;">没有找到任何数据</td></tr>');
		$this->display();
	}
	
	/**
     * 添加&&修改疾病症状页面
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function disSymptomaddedit(){
		$id = I('id',0); 
		$Modle = M('symptomsdisease');
		$data = array();
		$detail = $Modle->field('`id`,`appname`,`symptom`')->where('`id`='.$id)->find(); 
		$appname = $this->getApp();
		//加载内容控件js
		$js_editor = Resource::getStatic(array('ckeditor','ckfinder'),'js');
		$this->assign('id',$id);
		$this->assign('detail',$detail);
		$this->assign('appname',$appname);
		$this->assign('editor',$js_editor);
		$this->display();  
	}
	
	/**
     * 添加&&修改操作疾病症状页面
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function disSymptomaddedit_save(){
		$id = I('id',0); 
		$appname = I('appname',0);  //APP名称
		$symptom_list = trim($_POST['symptom']);  
		$symptom_list = split("\r\n", $symptom_list);  
		$symptom=implode("|",$symptom_list);
    	$Modle = M('symptomsdisease');
        $Modle->appname = $appname;
        $Modle->symptom = $symptom;
		if(!empty($id)){ //修改
			$Modle->update_time = time();  //更新时间
			$Modle->where('id='.$id)->save();
		}else{  //添加
			$Modle->adduser = session('dis_realname');  //添加者
			$Modle->create_time = time();  //创建时间
			$Modle->add();
		}
		$this->success('保存成功！', '/Admin/Disassistant/disSymptom');
	}
		
	/**
     * 保健知识列表
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function healthKnowledge(){
		$this->publiclist(0,'healthKnowledge');
	}
	
	/**
     * 检查标准列表
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function checkStandard(){
		$this->publiclist(1,'checkStandard');
	}
	
	/**
     * 疾病简介列表
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function disIntroduction(){
		$this->publiclist(2,'disIntroduction');
	}
	
	/**
     * 疾病遗传信息列表
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function disGenetic(){
		$this->publiclist(3,'disGenetic');
	}
	
	/**
     * 疾病预防列表
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function disPrevention(){
		$this->publiclist(4,'disPrevention');
	}
	
	/**
     * 疾病治疗列表
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function disTreatment(){
		$this->publiclist(5,'disTreatment');
	}
		
	/**
     * 公共的列表页 
     * @param $type 0:保健知识,1:检查标准,2:疾病简介,3:疾病遗传信息,4:疾病预防,5:疾病治疗
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function publiclist($type,$display){
		$perpage = C('PERPAGE');  //每页显示的页数
		$page = I('page',1);  //当前的页数
		$total = 0; //初始化总共显示的条数
		$Model = M('healthcaredrug');
		$aapmodel = M('app');
		$list = array();
		$list = $Model->field('`id`,`appname`,`content`,`update_time`,`adduser`,`create_time`')->where('`type`='.$type)->order('id desc')->limit(($page-1)*$perpage, $perpage)->select();
    	foreach ($list as $key=>$val){
    		$appname = $aapmodel->field('`appname`')->where('`id`='.$val['appname'])->find();
    		$list[$key]['appname']=$appname['appname'];
    	}
		$total = $Model->where('`type`='.$type)->count();
		$mypage = new Pager($total,$perpage,$page,'/Admin/Disassistant/'.$display);
		//类型显示
		$carray=array('保健知识摘要','检查标准','疾病简介摘要','疾病遗传信息','疾病预防摘要','疾病治疗摘要');
		$this->assign('type',$type);
		$this->assign('list',$list);
		$this->assign('carray',$carray[$type]);
		$this->assign('page',$mypage->show());
		$this->assign('empty','<tr><td colspan="7" style="text-align:center;">没有找到任何数据</td></tr>');
		$this->display('checkStandard');
	}
	
	/**
     * 添加&&修改（0:保健知识,1:检查标准,2:疾病简介,3:疾病遗传信息,4:疾病预防,5:疾病治疗）页面
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function checkStandardaddedit(){
		$id = I('id',0); 
		$type = I('type',0); //所属类型,默认是保健知识
		$Modle = M('healthcaredrug');
		$data = array();
		$detail = $Modle->field('`id`,`appname`,`geneticrisk`,`content`')->where('`id`='.$id)->find(); 
		$appname = $this->getApp();
		//加载内容控件js
		$js_editor = Resource::getStatic(array('ckeditor','ckfinder'),'js');
		//类型显示
		$carray=array('保健知识详情','检查标准','疾病简介','疾病遗传信息详情','疾病预防','疾病治疗');
		$this->assign('id',$id);
		$this->assign('type',$type);
		$this->assign('detail',$detail);
		$this->assign('appname',$appname);
		$this->assign('carray',$carray[$type]);
		$this->assign('editor',$js_editor);
		$this->display();  
	}
	
	/**
     * 添加&&修改操作（0:保健知识,1:检查标准,2:疾病简介,3:疾病遗传信息,4:疾病预防,5:疾病治疗）页面
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function checkStandardaddedit_save(){
		$id = I('id',0); 
		$appname = I('appname',0);  //APP名称
		$type = I('type',0);  //所属类别
		$geneticrisk = I('geneticrisk',0);  //遗传危险度
		$content = I('content');  //内容
    	$Modle = M('healthcaredrug');
        $Modle->create();
        //需要跳转的类型
        $carray=array('healthKnowledge','checkStandard','disIntroduction','disGenetic','disPrevention','disTreatment');
		if(!empty($id)){  //修改
			$Modle->update_time = time();  //更新时间
			$Modle->where('id='.$id)->save();
		}else{  //添加
			$Modle->adduser = session('dis_realname');  //添加者
			$Modle->create_time = time();   //创建时间
			$Modle->add();
		}
		$this->success('保存成功！', '/Admin/Disassistant/'.$carray[$type]);
	}
	
	/**
     * 用药知识管理
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function drugKnowledge(){
		$perpage = C('PERPAGE');  //每页显示的页数
		$page = I('page',1);  //当前的页数
		$total = 0; //初始化总共显示的条数
		$Model = M('knowledge');
		$aapmodel = M('app');
		$list = $Model->field('`id`,`appname`,`content`,`update_time`,`adduser`,`create_time`')->order('id desc')->limit(($page-1)*$perpage, $perpage)->select();
    	foreach ($list as $key=>$val){
    		$appname = $aapmodel->field('`appname`')->where('`id`='.$val['appname'])->find();
    		$list[$key]['appname']=$appname['appname'];
    	}
		$total = $Model->count();
		$mypage = new Pager($total,$perpage,$page,'/Admin/Disassistant/drugKnowledge');
		$this->assign('list',$list);
		$this->assign('page',$mypage->show());
		$this->assign('empty','<tr><td colspan="7" style="text-align:center;">没有找到任何数据</td></tr>');
		$this->display();
	}
	
	/**
     * 添加&&修改用药知识管理页面
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function drugKnowledgeaddedit(){
		$id = I('id',0); 
		$Modle = M('knowledge');
		$detail = $Modle->field('`id`,`appname`,`content`')->where('`id`='.$id)->find(); 
		$appname = $this->getApp();
		$js_editor = Resource::getStatic(array('ckeditor','ckfinder'),'js');
		$this->assign('id',$id);
		$this->assign('detail',$detail);
		$this->assign('appname',$appname);
		$this->assign('editor',$js_editor);
		$this->display();  
	}
	
	/**
     * 添加&&修改操作用药知识管理页面
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function drugKnowledgeaddedit_save(){
		$id = I('id',0); 
    	$Modle = M('knowledge');
        $Modle->create();
		if(!empty($id)){  //修改
			$Modle->update_time = time();  //更新时间
			$Modle->where('id='.$id)->save();
		}else{  //添加
			$Modle->adduser = session('dis_realname');  //添加者
			$Modle->create_time = time();  //创建时间
			$Modle->add();
		}
		$this->success('保存成功！', '/Admin/Disassistant/drugKnowledge');
	}
	
	/**
     * 疾病APPbanner管理
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function disAppBanner(){
		$perpage = C('PERPAGE');  //每页显示的页数
		$page = I('page',1);  //当前的页数
		$total = 0; //初始化总共显示的条数
		$Model=M('appbanner');
		$list = $Model->field('`id`,`name`,`imgurl`,`address`,`if_top`,`update_time`,`adduser`,`create_time`')->order('id desc')->limit(($page-1)*$perpage, $perpage)->select();
    	$total = $Model->count();
		$mypage = new Pager($total,$perpage,$page,'/Admin/Disassistant/disAppBanner');
		$this->assign('list',$list);
		$this->assign('page',$mypage->show());
		$this->assign('empty','<tr><td colspan="7" style="text-align:center;">没有找到任何数据</td></tr>');
		$this->display();
	}
	
	/**
     * 添加&&修改疾病APPbanner管理页面
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function disAppBanneraddedit(){
		$id = I('id',0); 
		$Modle = M('appbanner');
		$data = array();
		$detail = $Modle->field('`id`,`name`,`imgurl`,`address`,`if_top`')->where('`id`='.$id)->find(); 
		$this->assign('id',$id);
		$this->assign('detail',$detail);
		$this->display();  
	}
	
	/**
     * 添加&&修改操作疾病APPbanner管理页面
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-06
     */
	public function disAppBanneraddedit_save(){
		$id = I('id',0); 
		$name = I('name');  //banner名称
		$file = $_FILES['imgurl'];  //banner图片
		$address = I('address'); //banner地址
		$if_top = I('if_top'); //是否置顶
		if(!empty($file['size'])){
			if($file['size']>307200){   //判断上传图片大些
	    		$this->error('上传的图片不能为空且不能大于300k','/Admin/Disassistant/disAppBanner');
	    	}
    		$asksign = C('ASK_SIGN');
	    	$image = new Image();
	    	$imgurl = $image->uploadsingle($file,$asksign);
	    	$data['imgurl']=$imgurl;
    	}
		
    	$Modle = M('appbanner');
    	$data['name']=$name; 
    	$data['address']=$address;
    	$data['if_top']=$if_top;
		if(!empty($id)){  //修改
			$data['update_time'] = time();  //更新时间
			$Modle->where('id='.$id)->save($data);
		}else{  //添加
			$data['adduser'] = session('dis_realname');  //添加者
			$data['create_time'] = time();  //创建时间
			$Modle->add($data);
		}
		$this->success('保存成功！', '/Admin/Disassistant/disAppBanner');
	}
	
	/**
     * 发现模块管理
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-05
     */
	public function findModule(){
		$page = I('page',1);  //当前的页数
		$perpage = C('PERPAGE');  //每页显示的页数
		$total = 0;
		$Model=M('discoverymodule');
		$list = $Model->field('`id`,`name`,`icon`,`address`,`update_time`,`adduser`,`create_time`')->order('id desc')->limit(($page-1)*$perpage, $perpage)->select();
    	$total = $Model->count();
		$mypage = new Pager($total,$perpage,$page,'/Admin/Disassistant/findModule');
		$this->assign('list',$list);
		$this->assign('page',$mypage->show());
		$this->assign('empty','<tr><td colspan="7" style="text-align:center;">没有找到任何数据</td></tr>');
		$this->display();
	}
	
	/**
     * 添加&&修改发现模块管理页面
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-05
     */
	public function findModuleaddedit(){
		$id = I('id',0); 
		$Modle = M('discoverymodule');
		$data = array();
		$detail = $Modle->field('`id`,`name`,`icon`,`address`')->where('`id`='.$id)->find();
		$this->assign('id',$id);
		$this->assign('detail',$detail);
		$this->display();  
	}
	
	/**
     * 添加&&修改发现模块管理页面
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-05
     */
	public function findModuleaddedit_save(){
		$id = I('id',0); 
		$name = I('name');  //应用名称
		$file = $_FILES['icon'];  //应用ICON 
		$address = I('address'); //应用地址 
		if(!empty($file['size'])){
			if($file['size']>307200){   //判断上传图片大些
	    		$this->error('上传的图片不能为空且不能大于300k','/Admin/Disassistant/findModuleaddedit');
	    	}
    		$asksign = C('ASK_SIGN');
	    	$image = new Image();
	    	$imgurl = $image->uploadsingle($file,$asksign);
	    	$data['icon']=$imgurl;
    	}
    	$Modle = M('discoverymodule');
    	$data['name']=$name; 
    	$data['address']=$address;
		if(!empty($id)){  //修改
			$data['update_time'] = time();  //更新时间
			$Modle->where('id='.$id)->save($data);
		}else{  //添加
			$data['adduser'] = session('dis_realname');  //添加者
			$data['create_time'] = time();  //创建时间
			$Modle->add($data);
		}
		$this->success('保存成功！', '/Admin/Disassistant/findModule');
	}
	
	/**
     * APP网站信息管理
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-05
     */
	public function serviceAgreement(){
		$type = I('type',0);  //分类
		$Modle = M('websiteinformation');
		$data = array();
		$data = $Modle->field('`content`')->where('type='.$type)->find();
		//所属协议类型
		$typelist = array('用户注册协议','家庭医生服务协议','电话医生服务协议');
		//加载控件js
		$js_editor = Resource::getStatic(array('ckeditor','ckfinder'),'js');
		$this->assign('type',$type);
		$this->assign('data',$data);
		$this->assign('typelist',$typelist);
		$this->assign('editor',$js_editor);
		$this->display();  
	}
	
	/**
     * 添加&&修改APP网站信息管理
     * @auther zhoucuiyu@xywy.com
     * @version 2015-02-05
     */
	public function addeditserviceAgreement(){
		$type = I('type',0);  //分类
		$Modle = D('websiteinformation');
		$data = $Modle->field('`content`')->where('type='.$type)->find();
		if(!empty($data)){  //修改
			$Modle->create();
			$Modle->update_time=time();  //更新时间
			$Modle->where('type='.$type)->save();
		}else{  //添加
			$Modle->create();
			$Modle->adduser=session('dis_realname');  //添加者
			$Modle->create_time=time();  //创建时间
			$Modle->add();
		}
		$this->success('保存成功！', '/Admin/Disassistant/serviceAgreement/type/'.$type);
	}
}